package pers.twf.twfRpc.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;

public class ConfigUtils {

    /**
     * 加载配置对象
     * @param prefix
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T loadConfig(String prefix,Class<T> clazz){
        return loadConfig(prefix, clazz ,"");
    }

    private static <T> T loadConfig(String prefix, Class<T> clazz, String environment) {
        StringBuilder application = new StringBuilder("application");
//        支持环境区分
        if(StrUtil.isNotBlank(environment)){
            application.append("-").append(environment);
        }
        application.append(".properties");
        Props props = new Props(application.toString());
        return props.toBean(clazz,prefix);
    }
}

